function ans = ucordic8(data, m, approxmode)

	neg_atantable = int8([0x23, 0x10, 0x08, 0x04, 0x04, 0x02, 0x01, 0x01]);
	zro_atantable = int8([0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x01, 0x00]);
	pos_atantable = int8([0x32, 0x1e, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00]);

	neg_K = int8(0x4d);
	zro_K = int8(0x40);
	pos_K = int8(0x27);

	neg_Fi = int8([1, 2, 3, 4, 4, 5, 6, 7]);
	zro_Fi = int8([1, 2, 3, 4, 5, 6, 7, 8]);
	pos_Fi = int8([0, 1, 2, 3, 4, 5, 6, 7]);
	
	ans = int8(data);
	tempdata = ans;
	
	for i= 1 : 8
		if (m == -1)
			if (approxmode == 0)
				if (ans(2) >= 0)
					tempdata(1) = ans(1) - bitshift(ans(2), -1 .* neg_Fi(i));
					tempdata(2) = ans(2) - bitshift(ans(1), -1 .* neg_Fi(i));
					tempdata(3) = ans(3) + neg_atantable(i);
					ans = tempdata;
				else
					tempdata(1) = ans(1) + bitshift(ans(2), -1 .* neg_Fi(i));
					tempdata(2) = ans(2) + bitshift(ans(1), -1 .* neg_Fi(i));
					tempdata(3) = ans(3) - neg_atantable(i);
					ans = tempdata;
				endif
			else
				if (ans(3) < 0)
					tempdata(1) = ans(1) - bitshift(ans(2), -1 .* neg_Fi(i));
					tempdata(2) = ans(2) - bitshift(ans(1), -1 .* neg_Fi(i));
					tempdata(3) = ans(3) + neg_atantable(i);
					ans = tempdata;
				else
					tempdata(1) = ans(1) + bitshift(ans(2), -1 .* neg_Fi(i));
					tempdata(2) = ans(2) + bitshift(ans(1), -1 .* neg_Fi(i));
					tempdata(3) = ans(3) - neg_atantable(i);
					ans = tempdata;
				endif
			endif
		elseif (m == 0)
			if (approxmode == 0)
				if (ans(2) >= 0)
					tempdata(2) = ans(2) - bitshift(ans(1), -1 .* zro_Fi(i));
					tempdata(3) = ans(3) + zro_atantable(i);
					ans = tempdata;
				else
					tempdata(2) = ans(2) + bitshift(ans(1), -1 .* zro_Fi(i));
					tempdata(3) = ans(3) - zro_atantable(i);
					ans = tempdata;
				endif
			else
				if (ans(3) < 0)
					tempdata(2) = ans(2) - bitshift(ans(1), -1 .* zro_Fi(i));
					tempdata(3) = ans(3) + zro_atantable(i);
					ans = tempdata;
				else
					tempdata(2) = ans(2) + bitshift(ans(1), -1 .* zro_Fi(i));
					tempdata(3) = ans(3) - zro_atantable(i);
					ans = tempdata;
				endif
			endif
		elseif (m == 1)
			if (approxmode == 0)
				if (ans(2) >= 0)
					tempdata(1) = ans(1) + bitshift(ans(2), -1 .* pos_Fi(i));
					tempdata(2) = ans(2) - bitshift(ans(1), -1 .* pos_Fi(i));
					tempdata(3) = ans(3) + pos_atantable(i);
					ans = tempdata;
				else
					tempdata(1) = ans(1) - bitshift(ans(2), -1 .* pos_Fi(i));
					tempdata(2) = ans(2) + bitshift(ans(1), -1 .* pos_Fi(i));
					tempdata(3) = ans(3) - pos_atantable(i);
					ans = tempdata;
				endif
			else
				if (ans(3) < 0)
					tempdata(1) = ans(1) + bitshift(ans(2), -1 .* pos_Fi(i));
					tempdata(2) = ans(2) - bitshift(ans(1), -1 .* pos_Fi(i));
					tempdata(3) = ans(3) + pos_atantable(i);
					ans = tempdata;
				else
					tempdata(1) = ans(1) - bitshift(ans(2), -1 .* pos_Fi(i));
					tempdata(2) = ans(2) + bitshift(ans(1), -1 .* pos_Fi(i));
					tempdata(3) = ans(3) - pos_atantable(i);
					ans = tempdata;
				endif
			endif
		endif
	endfor
	return;
endfunction